//
// Created by yewei on 2021/9/20.
//

#include <bits/stdc++.h>

using namespace std;

const int MAXV = 1010;
struct node{
    int data;
    node* lchild;
    node* rchild;
};

void insertBST(node* &root,int x);
node* Create(int data[],int n);
void preOrder(node* tree);
void preOrderMirror(node* tree);
void postOrder(node* tree);
void postOrderMirror(node* tree);

int data[MAXV];
vector<int> preorder,preorderMirror;
vector<int> postorder,postorderMirror;

int main() {
    freopen("../A1043.txt", "r", stdin);
    int N;
    cin>>N;
    for(int i=0;i<N;i++) {
        cin >> data[i];
    }
    node* tree = Create(data,N);
    preOrder(tree);
    postOrder(tree);
    preOrderMirror(tree);
    postOrderMirror(tree);


    int i,j;
    for(i=0;i<N;i++){
        if(data[i]!=preorder[i]) break;
    }
    for(j=0;j<N;j++){
        if(data[j]!=preorderMirror[j]) break;
    }
    if(i==N){
        cout<<"YES"<<endl;
        for(int l=0;l<N;l++){
            if(l!=0) cout<<" ";
            cout<<postorder[l];
        }
    } else if(j==N){
        cout<<"YES"<<endl;
        for(int l=0;l<N;l++){
            if(l!=0) cout<<" ";
            cout<<postorderMirror[l];
        }
    } else{
        cout<<"NO"<<endl;
    }

    return 0;
}

void insertBST(node* &root,int x){
    if(root==nullptr){
        root = new node;root->lchild = root->rchild = nullptr;
        root->data = x;
        return;
    }

    if(x>=root->data){
        insertBST(root->rchild,x);
    }else{
        insertBST(root->lchild,x);
    }
}
node* Create(int data[],int n){
    node* root = nullptr;
    for(int i=0;i<n;i++){
        insertBST(root,data[i]);
    }
    return root;
}

void preOrder(node* tree){
    if(tree == nullptr) return;

    preorder.push_back(tree->data);
    if(tree->lchild!=nullptr) preOrder(tree->lchild);
    if(tree->rchild!=nullptr) preOrder(tree->rchild);
}
void preOrderMirror(node* tree){
    if(tree == nullptr) return;

    preorderMirror.push_back(tree->data);
    if(tree->rchild!=nullptr) preOrderMirror(tree->rchild);
    if(tree->lchild!=nullptr) preOrderMirror(tree->lchild);
}
void postOrder(node* tree){
    if(tree == nullptr) return;

    if(tree->lchild!=nullptr) postOrder(tree->lchild);
    if(tree->rchild!=nullptr) postOrder(tree->rchild);
    postorder.push_back(tree->data);
}
void postOrderMirror(node* tree){
    if(tree == nullptr) return;

    if(tree->rchild!=nullptr) postOrderMirror(tree->rchild);
    if(tree->lchild!=nullptr) postOrderMirror(tree->lchild);
    postorderMirror.push_back(tree->data);
}
